package javase.ch02.homeWork.Test3;

public class MyThread extends Thread{
    static int ticket = 0;

    @Override
    public void run() {
        while ( true){
            synchronized (MyThread.class){
                if(ticket<100){
                    ticket++;
                    System.out.println(Thread.currentThread().getName()+"正在卖第"+ticket+"张票"+" ,还剩"+(100-ticket)+"张票");
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }else{
                    System.out.println("票已卖完,下次早点来");
                    break;
                }
            }
        }
    }
}
